<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.UserMethods"%>

<script>
$("a.locals").click(function() {
		$("#events_content").hide().fadeIn(1000).load("main/localProfile.jsp?local_id="+ $(this).attr('id'));
		return false;
	});

$("a.events").click(function() {
	$("#events_content").hide().fadeIn(1000).load("events/eventProfile.jsp?event_id="+ $(this).attr('id'));
	return false;
});
</script>




<div class="page-header">
	<h2 class="page-title">Wydarzenia organizowane przeze mnie </h2>
</div>

<br />

<div id="content">
<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
					EventMethods em = new EventMethods();
						 Integer user_id = (Integer) session.getAttribute("user_id");
							response.setContentType("text/html");
							LocalMethods lm = new LocalMethods();
							if (user_id != null) {
								List<UserEvent> eplist = em.listOrganizingByUser(sessionFactory, s, user_id);
						
					%> 
					


<%
		if (eplist.size() > 0) {
			%>
			<table class="table">

<thead>
<tr>
<td>Nazwa wydarzenia</td>
<td>Lokal</td>
<td>Poczatek </td>
<td>Koniec</td>
<td> Usuń </td>
</tr>
</thead>
<%
	for (UserEvent ue : eplist) {
		String nazwa = ue.getEventname();
		int lokal_id = ue.getLocal_id();
		Local l = lm.findLocalById(sessionFactory, s, lokal_id);
		String localName = l.getCountry()+", "+l.getCity()+", "+ l.getStreet()+" "+l.getLocal_number();
		String poczatek = ue.getStart();
		String koniec = ue.getEnd();
		
		%>
		<tbody>
<tr>
<td><% out.println("<a class=\"events\" id=\""+ ue.getUserevent_id() + "\" href=\"#\">" + nazwa + "</a>"); %></td>
<td><% out.println("<a class=\"locals\" id=\""+ ue.getLocal_id() + "\" href=\"#\">" + localName + "</a>"); %> </td>
<td><% out.println(poczatek); %></td>
<td> <% out.println(koniec); %> </td>
<td> <form action="../DeleteUserEvent" method="Post" id="form">
<input type="hidden" id="userevent_id" name="userevent_id" value="<%out.print(ue.getUserevent_id()); %>">
<input type="submit" class="mainBtn" value="Usuń" />
</form>
</td>
</tr>
</tbody>		
		<%
		}
		} else{
			out.println("Nie organizujesz zadnego wydarzenia");
		}
		}
		
		s.getTransaction().commit();
		%>
		
		
		

</table>


</div>